package com.axjy.web;

import com.axjy.pojo.User;
import com.axjy.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * Created by asus on 2018/1/13.
 */
@Controller
@RequestMapping("/sys")
public class SysHandler {

    @Resource
    private UserService userService;

    @PostMapping("/login")
    public String login(String name,String pwd,Model model,HttpSession session){
        User loginUser=userService.login(name,pwd);
        if(loginUser==null){
            model.addAttribute("loginErr","用户名或密码错误");
            return "forward:/login.jsp";
        }
        session.setAttribute("loginUser",loginUser);
        return "redirect:/index";
    }

}
